// 桌面端布局
import Pc from "../layout/pc";
// 移动端布局
import Mini from "../layout/mini";

const pcPages = import.meta.glob("../ComputerViews/*.jsx", { eager: true });
const mobilePages = import.meta.glob("../MobileViews/*.jsx", { eager: true });
console.log('pcPages',pcPages);

// 路由配置
// 解析组件并生成路由
const generateRoutes = (pages, LayoutComponent) => {
  const children = Object.keys(pages).map((path) => {
    // 从文件路径中提取文件名
    const fileName = path.split("/").pop().replace(".jsx", "");
    const Component = pages[path].default;

    return {
      path: fileName.toLowerCase(), // 将文件名作为路径，例如 "HomePc" => "homepc"
      element: <Component />,
    };
  });

  // 返回顶层路由配置
  return [
    {
      path: "/",
      element: <LayoutComponent />,
      children,
    },
  ];
};

// 分别生成 PC 和 Mobile 的路由
export const routesMobile = generateRoutes(mobilePages, Mini);
export const routesComputer = generateRoutes(pcPages, Pc);